<?
$subframe = isset($_GET['subframe']) ? $_GET['subframe'] : "niit";
switch ($subframe){
	case "niit": $text = "Bản tin NIIT Việt Nam"; break;
	case "it":	$text = "Bản tin Công nghệ Thông tin"; break;
	case "cemina":	$text = "Hội thảo"; break;
	case "comp":	$text = "Cuộc thi"; break;
}
$frame = $_GET['frame'];
//$code = $_lang == 'vn' ? 'vn_news' : 'en_news';
$code = 'vn_'.$frame.'_'.$subframe;
$parentWhere = "and parent = (select id from tbl_content_category where code='$code')";
$parentRecord = getRecord("tbl_content","1=1 ".$parentWhere);
$cat = killInjection($_REQUEST['cat']);
if ($cat=='') $cat = $parentRecord['parent'];
$per_page =5;
$p = isset ( $_GET["p"] ) ? intval ( $_GET["p"] ) : 0; 

$sql = "select * from tbl_content where status=0 $parentWhere order by sort,date_added desc limit ".$per_page*$p.",".$per_page;
//echo $sql;
$result = @mysql_query($sql,$conn);
$num=mysql_num_rows($result);
//echo "so dong la: ".$num;
if($num==0){?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center"><font color="#FF0000" size="2">Thông tin đang cập nhật ...</font></td></tr>
</table>
<? }
else{?>
<div class="titledetaillist"><?=$text?></div>
        <div class="content">
<? 
while($row=mysql_fetch_assoc($result))
{
?>	
        	<div class="anews">
				<div class="picdetailleft"><a href="./?frame=news&subframe=<?=$subframe?>&id=<?=$row['id']?>"><img src="<?=$row['image']?>" width="90" height="90" border="0" /></a></div>
				<div class="title"><a href="./?frame=news&subframe=<?=$subframe?>&id=<?=$row['id']?>"><?=$row['name']?></a></div>
				<div class="time">Theo <?=$row['subject']?></div>
					<?=$row['detail_short']?>
			</div><!--endNews-->
<? 
}?>

<?
$total=countRecord("tbl_content","1=1 ".$parentWhere);	//dem so luong record
$number_of_page = ceil ( $total / $per_page );	//tong so trang
//echo "so trang la:".$number_of_page;
if ( $number_of_page > 0 )
{
	$list_page = " <td> Trang $p / $number_of_page: </td>";
	
	$pre = "./?frame=".$_REQUEST['frame']."&subframe=".$subframe."&p=".($p-1);
	if ($p >=1 )	//neu trang hien tai nho hon 2 thi ko co' ve truoc nua
		$list_page .= "<a title='Trang trước' href='".$pre."'><img width='12' height='12' border='0' align='bottom' src='Images/FirstPage.gif'></a>";
	for ( $i = $p -1 ; $i <= $p + 1; $i++ )	//chi hien thi 3 trang lien ke
	{		
		//neu trang hien tai thi in dam
		if ( $i == $p )
		{
			$list_page .= "  <a href=''><font color='red'><b>".$i."</b></font></a>  ";
		}
		else	//khong phai trang hien tai
		{
			if ($i >= 0 && $i < $number_of_page)
				$list_page .= "<a href=\"./?frame=".$_REQUEST['frame']."&subframe=".$subframe."&p=$i\"> ".$i." </a>";
		}
		
	}
	$next = "./?frame=".$_REQUEST['frame']."&subframe=".$subframe."&p=".($p+1);
	if ($p < $number_of_page - 1)
		$list_page .= "<a title='Trang sau' href='".$next."'><img width='12' height='12' border='0' align='bottom' src='Images/LastPage.gif'></a>";
}

print <<<EOF
<div class="pages">
{$list_page}
</div>
EOF;

?>

		</div>
<? }?>

